import 'package:flutter/material.dart';
import 'package:moli/HomePage/ui.dart';
import 'package:moli/ParseMarkdown/parser.dart';

import '../Gloabal.dart';

class HomePage extends StatefulWidget{
  final initContent = GlobalSettings.AppTabContent;
  final initHead = GlobalSettings.AppTabHead;
  var setTheme;

  HomePage(this.setTheme);

  @override
  State<StatefulWidget> createState() => _HomePage(setTheme);
}

class _HomePage extends State<HomePage>{
  List<MarkdownPage> _content = [];
  Key _tabKey = UniqueKey();
  int _index = 0;
  var setTheme;

  _HomePage(this.setTheme);

  @override
  void initState() {
    _content = widget.initContent;
    _index = 0;
    super.initState();
  }

  void updateState(currentTab,newContent) {
    setState(() {
      print("UPDATE!");
      _index = currentTab;
      _content = newContent;
      _tabKey = UniqueKey();
    });
  }

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
        key: _tabKey,
        initialIndex: _index,
        length: GlobalSettings.AppTabHead.length,
        child: Scaffold(
          drawer: MenuWidget(GlobalSettings.DrawerContent, updateState),
          appBar: AppBar(
            title: Center(child:BeautifulTitleWidget("print(\"MOLI\")")),
            actions: [AvatarWidget()],
            bottom: TabBar(tabs: GlobalSettings.AppTabHead),
          ),
          body: TabBarView(children: _content), // 响应式update
          floatingActionButton: FloatingButtonWidget(true,setTheme),
        ),
    );
  }
}